#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 5e5 + 10;
int n, m;
int s[N], f[N], q[N];

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
		s[i] += s[i - 1];
	}
	int h = 1, t = 0;
	for (int i = 1; i <= n; i++) {
		while (h <= t && s[q[t]] >= s[i - 1]) t--;
		q[++t] = i - 1;
		if (q[h] < i - m) h++;
		f[i] = s[i] - s[q[h]];
	}
	int res = -2e9;
	for (int i = 1; i <= n; i++) res = max(res, f[i]);
	cout << res << endl;
	return 0;
}